<template>
  <!--Modal重置密码-->
  <a-modal title="重置密码" :visible="visible" :confirm-loading="confirmLoading" @ok="handleOk" @cancel="handleCancel">
    <a-form ref="ruleForm" :model="form" :rules="rules" class="modalForm">
      <a-form-item prop="password">
        <BaseInput v-model="form.password" type="password" placeholder="请重置密码">
          <a-icon slot="prefix" type="lock" style="color: rgba(0, 0, 0, 0.25)" />
        </BaseInput>
      </a-form-item>
      <a-alert message="注：输入登陆密码后，将会重置此账号密码，并将初始密码发送短信至账号员工手机" banner />
    </a-form>
  </a-modal>
</template>

<script>
import { updataUserManagePsw } from '@/api/system/system'
export default {
  name: 'modalPsw',
  props: {
    visible: {
      value: false,
      type: Boolean,
    },
  },
  data() {
    return {
      rules: {
        password: [{ required: true, message: '请输入正确的内容', trigger: 'blur' }],
      },
      confirmLoading: false,
      form: {
        password: '',
      },
    }
  },
  created() {},
  methods: {
    /**
     *@desc  table列表密码重置提交
     *@param {}
     */
    handleOk(e) {
      this.$refs.ruleForm.validate((valid) => {
        if (!valid) {
          this.$message.warning("请填写完所有必填项信息")
          return
        }
        if (this.confirmLoading) return
        this.confirmLoading = true
        updataUserManagePsw(this.from)
          .then((res) => {
            this.confirmLoading = false
            if (res.status === 200) {
              //密码更改成功
              this.handleCancel()
            }
          })
          .catch((err) => {
            //密码更改失败
            this.confirmLoading = false
          })
      })
    },
    /**
     *@desc  table列表密码重置取消
     *@param {}
     */
    handleCancel(e) {
      this.$emit('handleCancel', false)
    },
  },
}
</script>

<style>
.modalForm .ant-form-item .ant-form-item-control-wrapper {
  width: 90%;
  padding-left: 10%;
}
</style>
